<!--

			PESQUISE A QUERY "CREATE IF NOT EXISTS"   !!!!!!
            
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="config/tinydropdown.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="config/estilo_index.css" />
<script type="text/javascript" src="config/jquery.js"></script>
<script type="text/javascript" src="config/jquery.maskedinput.js"></script>
<script type="text/javascript" src="config/tinydropdown.js"></script>
<script type="text/javascript" src="config/tiny_mce.js"></script>
<script type="text/javascript" src="config/marcar_desmarcar_tudo.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7",
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example word content CSS (should be your site CSS) this one removes paragraph margins
		content_css : "css/word.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- <script type="text/javascript" src="config/valida.js"></script> -->
</head>

<body>
	<div id="site">
		<?PHP
            include_once ("config/conn.php");
            
            //Chama e Inicia a sessão do arquivo logar.php
            session_start();
            
            //Verifica se a variável de nível de acesso está definida
            if (isset ($_SESSION['nivel']) && !empty ($_SESSION['nivel']))
            {
                $vnivel = $_SESSION['nivel'];
            }
            else
            {
                header ('location:common/login.php');
            }
            
            switch ($vnivel)
            {
                case 1:
                    if (isset ($_SESSION['nome']) && !empty ($_SESSION['nome']) && isset ($_SESSION['matricula']) && !empty ($_SESSION['matricula']) && isset($_SESSION['senha']) && !empty($_SESSION['senha']) && isset ($_SESSION['id']) && !empty ($_SESSION['id']))
                    {
                        $nome=$_SESSION['nome'];
                        $matricula=$_SESSION['matricula'];
                        $senha=$_SESSION['senha'];
						$id=$_SESSION['id'];
                        
                        $db="master";
                    }
                    else
                    {
                        header ('location:common/login.php');
                    }
                    break;
                //Para casos em que se precise escrever algo do tipo 'case a || b:', deve-se escrever 'case a: (quebra de linha) case b: (instruções). Consulte "http://stackoverflow.com/questions/207002/how-to-use-a-switch-case-or-in-php" para mais informações sobre essa técnica ("falling through")
                case 2:
                case 3:
                case 5:
                    if (isset ($_SESSION['matricula']) && !empty ($_SESSION['matricula']) && isset($_SESSION['senha']) && !empty($_SESSION['senha']) && isset ($_SESSION['id']) && !empty ($_SESSION['id']))
                    {
                        $matricula=$_SESSION['matricula'];
                        $senha=$_SESSION['senha'];
						$id=$_SESSION['id'];
                        
                        //Selecionando qual o data_base que iremos usar
                        if ($vnivel==2)
                        {
                            $db="administradores";
                        }
                        else if ($vnivel==3)
                        {
                            $db="professores";
                        }
                        else if ($vnivel==5)
                        {
                            $db="alunos";
                        }
                    }
                    else
                    {
                        header ('location:common/login.php');
                    }
                    break;
                case 4:
                    if (isset ($_SESSION['nome']) && !empty ($_SESSION['nome']) && isset($_SESSION['senha']) && !empty($_SESSION['senha']) && isset ($_SESSION['id']) && !empty ($_SESSION['id']))
                    {
                        $nome=$_SESSION['nome'];
                        $senha=$_SESSION['senha'];
						$id=$_SESSION['id'];
                        
                        $db="responsaveis";
                    }
                    else
                    {
                        header ('location:common/login.php');
                    }
                    break;
                default:
                    header ('location:common/login.php');
                    exit;
                    break;
            }
            
            //Verifica pela 2ª Vez se os dados estão corretos no banco de dados
            if ($vnivel == 1)
            {
                $sql = "SELECT Nome, Matricula, Senha FROM ".$db." WHERE Nome='$nome' AND Matricula='$matricula' AND Senha='$senha' AND Nivel='$vnivel'";
            }
            else if ($vnivel == 2 || $vnivel == 3 || $vnivel == 5)
            {
                $sql = "SELECT Matricula, Senha FROM ".$db." WHERE Matricula='$matricula' AND Senha='$senha' AND Nivel='$vnivel'";
            }
            else if ($vnivel == 4)
            {
                $sql = "SELECT Nome, Senha FROM ".$db." WHERE Nome='$nome' AND Senha='$senha' AND Nivel='$vnivel'";
            }
            else
            {
                echo '<script type="text/javascript">
                        alert ("Há algum erro na sua variável de nível de acesso! Informe-nos esse problema!");
                        history.back ();
                      </script>';
            }
            
            $result = mysql_query($sql) or die("Erro ao Logar ".mysql_error());
            
            $resultados = mysql_num_rows($result);
            
            if($resultados == 0)
            {
                //Sessão existir e não for igual ao DB será destruida a sessão e direcionada para login.php
                session_destroy();
                header('location:common/login.php');
                exit;
            }
        ?>
            <div class="nav">
                <ul id="menu" class="menu">
                    <li class="nodiv"><a href="index.php">Início</a></li>
                     <?PHP
                        if ($vnivel == 1)
                        {
                            echo '<li><a href="#">Minha página</a>
                                    <ul>
                                        <li><a href="index.php?page=common/meus_dados">Meus Dados</a></li>
                                        <li><a href="index.php?page=common/chec_com">Comunicação</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Master</a>
                                    <ul>
                                        <li><a href="index.php?page=master/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=master/listar">Listar</a></li>
                                        <li><a href="index.php?page=master/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Administradores</a>
                                    <ul>
                                        <li><a href="index.php?page=admins/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=admins/listar">Listar</a></li>
                                        <li><a href="index.php?page=admins/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Professores</a>
                                    <ul>
                                        <li><a href="index.php?page=profs/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=profs/listar">Listar</a></li>
                                        <li><a href="index.php?page=profs/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Responsáveis</a>
                                    <ul>
                                        <li><a href="index.php?page=responsaveis/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=responsaveis/listar">Listar</a></li>
                                        <li><a href="index.php?page=responsaveis/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Alunos</a>
                                    <ul>
                                        <li><a href="index.php?page=alunos/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=alunos/listar">Listar</a></li>
                                        <li><a href="index.php?page=alunos/interacao">Interagir</a></li>
                                        <li><a href="index.php?page=alunos/buscar_por_matricula">Postar Notas</a></li>
                                    </ul>
                                  </li>';
                        }
                        
                        if ($vnivel == 2)
                        {
                            echo '<li><a href="#">Minha página</a>
                                    <ul>
                                        <li><a href="index.php?page=common/meus_dados">Meus Dados</a></li>
                                        <li><a href="index.php?page=common/chec_com">Comunicação</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Master</a>
                                    <ul>
                                        <li><a href="index.php?page=master/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Administradores</a>
                                    <ul>
                                        <li><a href="index.php?page=admins/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Professores</a>
                                    <ul>
                                        <li><a href="index.php?page=profs/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=profs/listar">Listar</a></li>
                                        <li><a href="index.php?page=profs/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Responsáveis</a>
                                    <ul>
                                        <li><a href="index.php?page=responsaveis/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=responsaveis/listar">Listar</a></li>
                                        <li><a href="index.php?page=responsaveis/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Alunos</a>
                                    <ul>
                                        <li><a href="index.php?page=alunos/cadastro">Cadastrar</a></li>
                                        <li><a href="index.php?page=alunos/listar">Listar</a></li>
                                        <li><a href="index.php?page=alunos/interacao">Interagir</a></li>
										<li><a href="index.php?page=alunos/postagem_notas">Postar Notas</a></li>
                                    </ul>
                                  </li>';
                        }
                        
                        if ($vnivel == 3)
                        {
                            echo '<li><a href="#">Minha página</a>
                                    <ul>
                                        <li><a href="index.php?page=common/meus_dados">Meus Dados</a></li>
                                        <li><a href="index.php?page=common/chec_com">Comunicação</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Master</a>
                                    <ul>
                                        <li><a href="index.php?page=master/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Administradores</a>
                                    <ul>
                                        <li><a href="index.php?page=admins/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Professores</a>
                                    <ul>
                                        <li><a href="index.php?page=profs/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Responsáveis</a>
                                    <ul>
                                        <li><a href="index.php?page=responsaveis/listar">Listar</a></li>
                                        <li><a href="index.php?page=responsaveis/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Alunos</a>
                                    <ul>
                                        <li><a href="index.php?page=alunos/listar">Listar</a></li>
                                        <li><a href="index.php?page=alunos/interacao">Interagir</a></li>
										<li><a href="index.php?page=alunos/postagem_notas">Postar Notas</a></li>
                                    </ul>
                                  </li>';
                        }
                        
                        if ($vnivel == 4)
                        {
                            echo '<li><a href="#">Minha página</a>
                                    <ul>
                                        <li><a href="index.php?page=common/meus_dados">Meus Dados</a></li>
                                        <li><a href="index.php?page=common/chec_com">Comunicação</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Administradores</a>
                                    <ul>
                                        <li><a href="index.php?page=admins/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Professores</a>
                                    <ul>
                                        <li><a href="index.php?page=profs/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
                                  
                                  <li><a href="#">Alunos</a>
                                    <ul>
                                        <li><a href="index.php?page=alunos/listar">Listar</a></li>
                                    </ul>
                                  </li>';
                        }
						
						if ($vnivel == 5)
                        {
                            echo '<li><a href="#">Minha página</a>
                                    <ul>
                                        <li><a href="index.php?page=common/meus_dados">Meus Dados</a></li>
                                        <li><a href="index.php?page=common/chec_com">Comunicação</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Administradores</a>
                                    <ul>
                                        <li><a href="index.php?page=admins/interacao">Interagir</a></li>
                                    </ul>
                                  </li>
								  
								  <li><a href="#">Professores</a>
                                    <ul>
                                        <li><a href="index.php?page=profs/interacao">Interagir</a></li>
                                    </ul>
                                  </li>';
                        }
                    ?>
                    <li><a href="common/logout.php">Logout</a></li>
               </ul>
        </div>
        
        <script type="text/javascript">
            var dropdown=new TINY.dropdown.init("dropdown", {id:"menu", active:"menuhover"});
        </script>
        
        <div id="conteudo">
            <?PHP
                $page = isset($_GET["page"]) ? $_GET["page"] : false;
                
                if (($page))
                {
                    include ("$page.php");
                }
                else
                {
                    include ("common/home.php");
                }
            ?>
        </div>
        <?php
            mysql_close ();
        ?>
    </div>
</body>
</html>